using TLDNs;
using NUnit.Framework;
using System.Collections;

namespace TLDNs.Tests
{
    [TestFixture()]
    public class UnitTest1
    {
        GifImage gif;
        [Test()]
        public void AddTest()
        {
            Assert.Zero(gif.Add(2, -2));

        }

        [Test()]
        public void Add2Test()
        {
            Assert.AreEqual(9, gif.Add(3, 6));
            Assert.Less(8, gif.Add(3, 6), "8<9");
        }

        [SetUp]
        public void Setup()
        {
            gif = new GifImage();
        }


        [TestCase(int.MaxValue, 2, Author = "su")]
        public void AddTest(int a, int b)
        {
            Assert.That(1 == gif.Add(a, b), "Fail");

        }

        [TestCase(1, 2, Author = "su")]
        public void AddTest1(int a, int b)
        {
            Assert.That(3 == gif.Add(a, b), "Fail");

            string[] strings = new string[] { "a", "ab", "abc" };
            int[] lengths = new int[] { 1, 2, 3 };

            Assert.That(List.Map(strings).Property("Length"), Is.EqualTo(lengths));
            Assert.That(new ListMapper(strings).Property("Length"), Is.EqualTo(lengths));
        }
    }


    [TestFixture]
    public class MyTests
    {
        GifImage gif;
        [SetUp]
        public void Setup()
        {
            gif = new GifImage();
        }


        [TestCaseSource(typeof(MyDataClass), "TestCases")]
        public int GifImageAddTest(int a, int b)
        {
            return gif.Add(a,b);
        }
    }

    public class MyDataClass
    {
        public static IEnumerable TestCases
        {
            get
            {
                yield return new TestCaseData(12, 3).Returns(15);
                yield return new TestCaseData(12, 2).Returns(14);
                yield return new TestCaseData(12, 4).Returns(16);
            }
        }
    }


    [TestFixtureSource(typeof(MyFixtureData), "FixtureParms")]
    public class ParameterizedTestFixture
    {
        private string eq1;
        private string eq2;
        private string neq;

        public ParameterizedTestFixture(string eq1, string eq2, string neq)
        {
            this.eq1 = eq1;
            this.eq2 = eq2;
            this.neq = neq;
        }

        public ParameterizedTestFixture(string eq1, string eq2)
            : this(eq1, eq2, null) { }

        public ParameterizedTestFixture(int eq1, int eq2, int neq)
        {
            this.eq1 = eq1.ToString();
            this.eq2 = eq2.ToString();
            this.neq = neq.ToString();
        }

        [Test]
        public void TestEquality()
        {
            Assert.AreEqual(eq1, eq2);
            if (eq1 != null && eq2 != null)
                Assert.AreEqual(eq1.GetHashCode(), eq2.GetHashCode());
        }

        [Test]
        public void TestInequality()
        {
            Assert.AreNotEqual(eq1, neq);
            if (eq1 != null && neq != null)
                Assert.AreNotEqual(eq1.GetHashCode(), neq.GetHashCode());
        }
    }


    public class MyFixtureData
    {
        public static IEnumerable FixtureParms
        {
            get
            {
                yield return new TestFixtureData("hello", "hello", "goodbye");
                yield return new TestFixtureData("zip", "zip");
                yield return new TestFixtureData(42, 42, 99);
            }
        }
    }

    public class GifImage
    {
       public  int Add(int a, int b)
        {
            return a + b;
        }
    }

}

